﻿using System.Collections;

namespace MyAssetBundles {
    public interface IFolder {
        void Generate (string path, IFolderProgress progress);
    }

    public interface IFolderEnumerator {
        IEnumerator GenerateEnumerator (string path, IFolderProgress progress);
    }

    public class BaseFolder : MonoFolder {
        protected FolderProgress _progress;
        protected MyAssetBundlesUpdateMode _updateMode;
        public void Init (MyAssetBundlesUpdateMode updateMode)
        {
            _updateMode = updateMode;
        }

        public void Init (BaseFolder target)
        {
            foreach (var v in target)
            {
                Add(v.Key, v.Value);
            }

            Init(target._updateMode);
        }

        protected void SetProgress (IFolderProgress progress, long total)
        {
            _progress = progress as FolderProgress;
            if (_progress == null) return;
            _progress.target.totalNum = total;
        }

        protected void SetProgress (float progress)
        {
            if (_progress == null) return;
            _progress.target.progress = float.Parse(progress.ToString("f3"));
            _progress.SetProgress();
        }

        protected void SetProcessNum (long process)
        {
            if (_progress == null || _progress.target.totalNum == 0) return;
            SetProgress((float)process / _progress.target.totalNum);
        }

        protected void SetFileNameCurr (string fileName)
        {
            if (_progress == null) return;
            _progress.target.fileNameCurr = fileName;
            _progress.SetProgress();
        }
    }
}

